What is path-browserify?
The path-browserify npm package is a version of Node.js core path module for the browser. It provides utilities for working with file and directory paths, allowing you to perform operations such as normalization, joining, and resolving paths in a way that is compatible with browser environments.
What are path-browserify's main functionalities?
Normalization
Normalize a string path, taking care of '..' and '.' parts and multiple slashes.
const path = require('path-browserify');
const normalizedPath = path.normalize('/foo/bar//baz/asdf/quux/..');
Joining Paths
Join all arguments together and normalize the resulting path.
const path = require('path-browserify');
const joinedPath = path.join('/foo', 'bar', 'baz/asdf', 'quux', '..');
Resolving Paths
Resolve a sequence of paths or path segments into an absolute path.
const path = require('path-browserify');
const resolvedPath = path.resolve('foo/bar', '/tmp/file/', '..', 'a/../subfile');
Basename
Get the last portion of a path, similar to the Unix basename command.
const path = require('path-browserify');
const base = path.basename('/foo/bar/baz/asdf/quux.html');
Extension Name
Return the extension of the path, from the last occurrence of the '.' (period) character to end of string in the last portion of the path.
const path = require('path-browserify');
const ext = path.extname('index.html');
Directory Name
Return the directory name of a path, similar to the Unix dirname command.
const path = require('path-browserify');
const dir = path.dirname('/foo/bar/baz/asdf/quux');
Other packages similar to path-browserify
path
This is the original Node.js path module itself. It provides the same functionality as path-browserify but is intended for use in Node.js server-side environments rather than the browser.
path-webpack-plugin
A plugin for webpack that allows you to use the Node.js path module in browser environments. It is similar to path-browserify but is specifically tailored for integration with webpack's module bundling system.
upath
A path manipulation library that extends the Node.js path module's functionality. It adds features like preserving trailing slashes and normalizing paths to a consistent format, which can be useful in certain situations. It is an alternative to path-browserify with some additional features.
path-browserify
The path
module from Node.js for browsers
This implements the Node.js path
module for environments that do not have it, like browsers.
path-browserify
currently matches the Node.js 10.3 API.
Install
You usually do not have to install path-browserify
yourself! If your code runs in Node.js, path
is built in. If your code runs in the browser, bundlers like browserify or webpack include the path-browserify
module by default.
But if none of those apply, with npm do:
npm install path-browserify
Usage
var path = require('path')
var filename = 'logo.png';
var logo = path.join('./assets/img', filename);
document.querySelector('#logo').src = logo;
API
See the Node.js path docs. path-browserify
currently matches the Node.js 10.3 API.
path-browserify
only implements the POSIX functions, not the win32 ones.
Contributing
PRs are very welcome! The main way to contribute to path-browserify
is by porting features, bugfixes and tests from Node.js. Ideally, code contributions to this module are copy-pasted from Node.js and transpiled to ES5, rather than reimplemented from scratch. Matching the Node.js code as closely as possible makes maintenance simpler when new changes land in Node.js.
This module intends to provide exactly the same API as Node.js, so features that are not available in the core path
module will not be accepted. Feature requests should instead be directed at nodejs/node and will be added to this module once they are implemented in Node.js.
If there is a difference in behaviour between Node.js's path
module and this module, please open an issue!
License
MIT